local Led = {}

local pin = 4
local flash_timer

function Led:Flash(delay)
    local flag = true
    delay = delay or 500
    
    flash_timer = tmr.create()
    flash_timer:register(delay, tmr.ALARM_AUTO, function (t) 
        if flag then
            self:Open()
        else
            self:Close()
        end
        flag = not flag 
    end)

    flash_timer:start()
end

function Led:StopFlash() 
    flash_timer:stop()
    flash_timer:unregister()
    self:Close()
end

function Led:Open() 
    gpio.mode(pin, gpio.OUTPUT)
    gpio.write(pin, gpio.LOW)
end

function Led:Close() 
    gpio.write(pin, gpio.HIGH)
end

return Led
